@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            添加产品分类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/proCategory" class="btn btn-primary">返回</a>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">ProductCategory</a></li>
            <li class="active">Add ProductCategory</li>
        </ol>
    </section>

    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">Quick Example</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form action="/product/productCategory/addProductCategory" method="post" role="form" style="width: 50%;">
                        {{csrf_field()}}
                        <div class="box-body">
                            <div class="form-group">
                                <label for="exampleInputEmail1">选择父级分类</label>
                                <select name="parent_id" class="form-control">
                                    <option value="0">一级分类</option>
                                    @foreach($one as $o)
                                        <option value="{{ $o['id'] }}">{{ $o['name'] }}</option>
                                    @endforeach
                                </select>

                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">分类名称</label>
                                <input type="text" name="name" class="form-control" placeholder="Category Name">
                            </div>
                            <span id="attachment" style="display: none">product/attachment/</span>
                            <span id="picture" style="display: none">product/picture/</span>
                            <div class="form-group">
                                <label for="exampleInputPassword1">图标</label>
                                <div id="container">
                                    <a id="selectfiles" href="javascript:void(0);" class='btn btn-primary'>选择文件</a>
                                    {{--<a id="postfiles" href="javascript:void(0);" class='btn btn-primary'>开始上传</a>--}}
                                </div>
                                <div class='clear container'>
                                    <!--<div id="dd" class="row"></div>-->
                                    <div id="ossfile"></div>
                                </div>
                                <div class='clear container'>
                                    <!--<div id="dd" class="row"></div>-->
                                    <div id="img"></div>
                                </div>
                                <input type="hidden" name="path" value="" id="getpath">
                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
@stop

@section('script')
    <script type="text/javascript" src="/oss/upload_pic.js"></script>
    <script>
        $(function() {
            $("form").submit(function(event) {
                event.preventDefault();
                var url = $(this).attr("action");
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });
                $.ajax({
                    url: url,
                    type: "POST",
                    data: $("form").serialize(),
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        window.location.href = window.location.href;
                        if(data.error == 0) {

                            layer.msg(data.msg,{icon:1});
                        }
                        else {
                            layer.msg(data.msg,{icon:2})
                        }
                    }
                });
            });
        });
    </script>

@stop